#include "refraction_effect.h"
#include "geometry/point.h"
#include "graphics/cube_texture_gl.h"
#include "graphics/error_gl.h"

namespace venus {
RefractionEffect::RefractionEffect(float eta_ratio) : eta_ratio_(eta_ratio) {
  Info("RefractionEffect::RefractionEffect");
  program_.Load("shaders/refraction.vp", "shaders/refraction.fp");
  program_.Link();
  eye_pos_var_ = program_.GetUniformVar("eye_pos");
  //material_color_var_ = program_.GetUniformVar("material_color");
  env_map_var_ = program_.GetUniformVar("env_map");
  eta_ratio_var_ = program_.GetUniformVar("eta_ratio");
}
void RefractionEffect::Begin() const {
  program_.Begin();
  glUniform3fv(eye_pos_var_, 1, eye_pos_->ptr());
  //glUniform4fv(material_color_var_, material_color_->ptr());
  glUniform1i(env_map_var_, env_map_);
  glUniform1f(eta_ratio_var_, eta_ratio_);
}

void RefractionEffect::End() const {
  program_.End();
}
} // namespace venus
